package com.example.controller;

import com.alibaba.fastjson.JSON;
import com.example.entity.ResponseEntity;
import com.example.entity.Vote;
import com.example.entity.VoteJson;
import com.example.entity.VoteMeg;
import com.example.service.impl.VoteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 陈俊杰
 */
@RestController
@RequestMapping
public class VoteController {

    @Autowired
    private VoteService voteService;

    /**
     * 添加一次投票信息
     * @param v
     * @return
     */
    @PostMapping("/addVote")
    public String addVote(@RequestBody VoteJson v){
        return voteService.addVote(v.getVote(),v.getList());
    }

    /**
     * 查询所有投票信息
     * @return
     */
    @GetMapping("/getAllVoteMeg")
    public ResponseEntity getAllVoteMeg(){
        return ResponseEntity.ok(voteService.getAllVote());
    }

    /**
     * 查询一次投票记录
     * @param id
     * @return
     */
    @PostMapping("/getOneVote/{id}")
    public ResponseEntity getOneVote(@PathVariable String id){
        return ResponseEntity.ok(voteService.getOneVote(id));
    }

    /**
     * 截止投票
     * @param id
     */
    @PostMapping("/offVote/{id}")
    public void offVote(@PathVariable String id){
        voteService.offVote(id);
    }
}
